package com.noah.project

import com.corundumstudio.socketio.SocketIOServer
import com.corundumstudio.socketio.annotation.SpringAnnotationScanner
import com.noah.project.global.Const
import org.mybatis.spring.annotation.MapperScan
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.Bean
import org.springframework.web.socket.server.standard.ServerEndpointExporter

@MapperScan("com.noah.project.dao")
@SpringBootApplication
open class MyApplication {

    //netty-socketio
    @Bean
    fun socketIOServer(): SocketIOServer {
        val config = com.corundumstudio.socketio.Configuration()
        //config.setHostname("172.16.2.175")
        config.setPort(Const.BASE_NETTY_PORT)
        config.pingTimeout = 125000;
        config.pingInterval = 60000;
        config.upgradeTimeout = 10000;
        /*config.setAuthorizationListener(new AuthorizationListener() {//类似过滤器
                @Override
                public boolean isAuthorized(HandshakeData data) {
                    //http://localhost:8081?username=test&password=test
                    //例如果使用上面的链接进行connect，可以使用如下代码获取用户密码信息，本文不做身份验证
                    // String username = data.getSingleUrlParam("username");
                    // String password = data.getSingleUrlParam("password");
                    return true;
                }
            });*/
        return SocketIOServer(config)
    }

    //netty-socketio
    @Bean
    fun springAnnotationScanner(socketServer: SocketIOServer): SpringAnnotationScanner {
        return SpringAnnotationScanner(socketServer)
    }

    //websocket
    /*@Bean
    fun serverEndpointExporter(): ServerEndpointExporter {
        return ServerEndpointExporter()
    }*/
}

fun main(args: Array<String>) {
    SpringApplication.run(MyApplication::class.java, *args)
}